﻿#if LOCK_STEP
using FLOAT = SoftFloat.sfloat;
#else
using FLOAT = System.Single;
#endif

namespace GameDesigner
{
    [HideBehaviour]
    public class ActionCoreBase : ActionBehaviour
    {
        /// <summary>
        /// 动画事件时间
        /// </summary>
		public FLOAT animEventTime = 50f;
        /// <summary>
        /// 是否已到达事件时间或超过事件时间，到为true，没到为flase
        /// </summary>
		[HideField]
        protected bool eventEnter;

        public override void OnEnter()
        {
            eventEnter = false;
        }

        public override void OnUpdate()
        {
            AnimationEvent();
        }

        private void AnimationEvent()
        {
            if (Action.animTime >= animEventTime & !eventEnter)
            {
                eventEnter = true;
                OnAnimationEvent();
            }
        }

        /// <summary>
        /// 当动画事件触发
        /// </summary>
        public virtual void OnAnimationEvent() { }

        public override void OnExit()
        {
            //防止动画进度100设置事件帧为100时不触发的问题
            AnimationEvent();
            eventEnter = false;
        }

        public override void OnStop()
        {
            //防止动画进度100设置事件帧为100时不触发的问题
            AnimationEvent();
        }
    }
}
